
#include "kernel_tim2_trigger.h"


unsigned int kernel_tim2_trigger_config(void) 
{ 
    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; 
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); 
    
    TIM_TimeBaseStructure.TIM_Period    = TIM2_PERIOD;
    TIM_TimeBaseStructure.TIM_Prescaler = TIM2_PRESCALER;
    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; 
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseInit(TIM2, & TIM_TimeBaseStructure); 
    
    TIM_SelectOutputTrigger(TIM2,TIM_TRGOSource_Update);
    TIM_ClearFlag(TIM2,TIM_FLAG_Update);
    
    TIM_OCInitTypeDef TIM_OCInitStructure; 
    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
    TIM_OCInitStructure.TIM_Pulse = 10;
    TIM_OC2Init(TIM2, & TIM_OCInitStructure);    
    TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable); 
    
    TIM_Cmd(TIM2, ENABLE);
    TIM_CtrlPWMOutputs(TIM2, ENABLE);
    
//    TIM_InternalClockConfig(TIM2); 
//    TIM_UpdateDisableConfig(TIM2, DISABLE); 
    
//    TIM_OCInitTypeDef TIM_OCInitStructure; 
//    TIM_OCStructInit(&TIM_OCInitStructure); 
//    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
//    TIM_OCInitStructure.TIM_Pulse = 20;
//    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;     
//    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;          
//    TIM_OC2Init(TIM2, &TIM_OCInitStructure);
// 
//    TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);  
//    TIM_ARRPreloadConfig(TIM2, ENABLE);
//    TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable);
//    TIM_Cmd(TIM2, ENABLE);
//    TIM_CtrlPWMOutputs(TIM2, ENABLE);
    
    return 1;
} 

